home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14539 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: solon.com!not-for-mail
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c.moderated,comp.lang.c
  4. Subject: Re: fflush(stdin) - not guaranteed to work?
  5. Followup-To: comp.lang.c.moderated,comp.lang.c
  6. Date: 15 Apr 1996 13:08:03 -0500
  7. Organization: TRIUMF: Tri-University Meson Facility
  8. Sender: clc@solutions.solon.com
  9. Approved: clc@solutions.solon.com
  10. Message-ID: <4ku3a3$4u9@solutions.solon.com>
  11. References: <4ksjpn$rjt@solutions.solon.com>
  12. NNTP-Posting-Host: solutions.solon.com
  13.  
  14. In article <4ksjpn$rjt@solutions.solon.com>, gohel@csee.usf.edu writes...
  15. >In Paul S. Wang's "Introduction to ANSI C on UNIX" he says that
  16. >the fflush() function was "not intended to control input buffering"
  17. >on page 266.
  18.  
  19. I believe the C standard agrees with him.  :-)
  20.  
  21. >What is the best way to get rid of the '\n' from the input buffer after
  22. >a scanf() statement?  In the same book on page 263 I've seen the following
  23. >format used in an fscanf() format specifier:
  24.  
  25. don't use scanf() for direct user input - besides the "leftover '\n'" problem,
  26. it can cause great grief if the user enters a letter when scanf() is expecting
  27. a number.
  28.  
  29. A better input procedure is to get a line with fgets(), then parse it with
  30. sscanf(), strtok(), or other functions.
  31.  
  32. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  33. Internet: bennett@triumf.ca         | of one another only when one can be
  34. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  35. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  36. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  37. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  38.